﻿using Tele.DataModels;
using Tele.db;
using Tele.db.IDataAdapters.Adapters;
using Tele.db.IDataAdapters.Interfaces;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Tele.Controllers
{
    public class HomeController : Controller
    {
        ITVShowAdapter _adapter;
        public HomeController()
        {
            _adapter = new TVShowAdapter();
        }
        public HomeController(ITVShowAdapter adapter)
        {
            _adapter = adapter;
        }
        public ActionResult Index()
        {
            List<TVShow> tvshows = _adapter.GetAllTVShows();
            return View(tvshows);
        }

        public ActionResult DetailsTVShow(int id)
        {
            TVShow tvshow = _adapter.GetTVShow(id);
            return View(tvshow);
           
        }
        [HttpGet]
        public ActionResult AddTVShow()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddTVShow(string title, string image, string yearsactive)
        {
            TVShow tvshow = new TVShow();
            tvshow.Title = title;
            tvshow.Image = image;
            tvshow.YearsActive = yearsactive;
         
            return RedirectToAction("DetailsTVShow/" + tvshow.Id);
        }
        [HttpGet]
        public ActionResult UpdateTVShow(int id)
        {
            TVShow tvshow;
            tvshow = _adapter.GetTVShow(id);
            return View(tvshow);
        }
        [HttpPost]
        public ActionResult UpdateTVShow(TVShow tvshow)
        {
            tvshow = _adapter.UpdateTVShow(tvshow);
            return RedirectToAction("DetailsTVShow/" + tvshow.Id);
        }
        [HttpPost]
        public ActionResult DeleteTVShow(int id)
        {
           _adapter.DeleteTVShow(id);
            return RedirectToAction("Index");
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}